﻿namespace MSpecTests.WhoCanHelpMe.Web.Controllers
{
    #region Using Directives

    using System.Web.Mvc;

    using global::WhoCanHelpMe.Domain.Contracts.Tasks;
    using global::WhoCanHelpMe.Web.Controllers.Home;
    using global::WhoCanHelpMe.Web.Controllers.Navigation;
    using global::WhoCanHelpMe.Web.Controllers.Navigation.ViewModels;
    using Machine.Specifications;

    using Rhino.Mocks;

    #endregion

    public abstract class specification_for_navigation_controller
    {
        protected static NavigationController sut;

        protected static IIdentityTasks identity_tasks;

        Establish context = () =>
        {
            identity_tasks = MockRepository.GenerateStub<IIdentityTasks>();
        };

        protected static void CreateSut()
        {
            sut = new NavigationController(identity_tasks);
        }
    }

    [Subject(typeof(HomeController))]
    public class when_the_navigation_controller_is_asked_for_the_header : specification_for_navigation_controller
    {
        static ActionResult result;

        Establish context = () =>
        {
            identity_tasks.Stub(i => i.IsSignedIn()).Return(true);

            CreateSut();
        };

        Because of = () => result = sut.Menu();

        It should_ask_the_identity_tasks_if_the_user_is_signed_in = () => 
            identity_tasks.AssertWasCalled(x => x.IsSignedIn());

        It should_return_the_default_view = () => result.IsAViewAnd().ViewName.ShouldBeEmpty();

        It should_not_use_a_master_page = () => result.IsAViewAnd().MasterName.ShouldBeEmpty();

        It should_set_the_view_model_property_to_a_new_menu_view_model = () => 
            result.IsAViewAnd().ViewData.Model.ShouldBeOfType(typeof(MenuViewModel));

        It should_set_the_properties_of_the_view_model_correctly = () => 
            (result.IsAViewAnd().ViewData.Model as MenuViewModel).IsLoggedIn.ShouldBeTrue();
    }
}
